package com.controller.purchase;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.common.DateUtils;
import com.common.DesUtils;
import com.common.http.HttpResult;
import com.model.purchase.PurchaseInquiryVO;
import com.model.purchase.PurchaseNeedMm;
import com.model.purchase.PurchaseNeedVO;
import com.service.purchase.NeedService;

import java.io.IOException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

/**
 * 需求计划管理
 */
@Controller
@RequestMapping(value = "/api")
public class NeedController {

	static final Logger logger = LoggerFactory.getLogger(NeedController.class);
	
	@Autowired
	NeedService needService;
	


	/**
	 * 查询列表
	 * 
	 * @param map
	 * @return
	 */
	@RequestMapping(value = "/purchase/need/selectNeedList", method = { RequestMethod.POST })
	@ResponseBody
	public HttpResult selectNeedList(@RequestParam Map<String, Object> map) {
		return needService.selectNeedList(map);
	}


	/**
	 * 查询明细列表
	 * 
	 * @param map
	 * @return
	 */
	@RequestMapping(value = "/purchase/need/selectNeedMmList", method = { RequestMethod.POST })
	@ResponseBody
	public HttpResult selectNeedMmList(@RequestParam Map<String, Object> map) {
		return needService.selectNeedMmList(map);
	}

	/**
	 * 导出
	 * 
	 * @param map
	 * @param response
	 * @throws IOException
	 */
	@RequestMapping(value = "/purchase/need/exportNeed")
	public void exportNeed(@RequestParam Map<String, Object> map, HttpServletResponse response) throws IOException {
		response.setContentType("application/vnd.ms-excel");
		response.setCharacterEncoding("utf-8");
		String fileName = URLEncoder.encode("需求计划-" + DateUtils.getCurrentDate(), "UTF-8");
		response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
		needService.exportNeed(map, response);

	}

}
